#ifndef __ATOS_UART_H__
#define	__ATOS_UART_H__

#include <stdint.h>
#include <stdio.h>
#include "atos_fifo.h"

#define     ATOS_UART_COUNT     	5

typedef struct atos_uart_device_t
{
	uint8_t fd;
	atos_fifo_t fifo;
} atos_uart_device_t;

typedef atos_uart_device_t *atos_uart_fd_t;

#define 	ATOS_UART_INVALID_FD 		NULL

/* Private function prototypes -----------------------------------------------*/

#ifdef __GNUC__
  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif
/* __GNUC__ */

void atos_uart_init();

atos_uart_fd_t atos_uart_open(
        const char * port_name,
        uint32_t baud_rate,
        uint8_t *buf,
        uint16_t size);

uint16_t atos_uart_send_byte(atos_uart_fd_t fd, uint8_t byte);
uint16_t atos_uart_send_data(atos_uart_fd_t fd, const void *buf, uint16_t len);
uint16_t atos_uart_receive_data(atos_uart_fd_t fd, void *buf, uint16_t len);
uint16_t atos_uart_receive_byte(
        atos_uart_fd_t fd,
        uint8_t *data);

#endif